<?php
/**
 * 外部用户中心登录
 * 
 * @version $Id: Login.php 408 2012-08-15 09:56:09Z linsir123 $
 */
class controllerLogin extends Controller  
{
	/**
	 * @var 模型
	 */
	public $mUser;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		$this->mUser = M::user();
	}
	
	/**
	 * QQ登录
	 */
	public function actionQQ()
	{
		$url = M::qq()->getLoginUrl();
		header('Location:'.$url);
	}
	
	/**
	 * QQ回调
	 */
	public function actionQQCallback()
	{
		M::qq()->callbackHandler();
		///
		$this->_checkLogin();
	}
	
	/**
	 * 新浪微博登录
	 */
	public function actionSina()
	{
		$url = M::sina()->getLoginUrl();
		header('Location:'.$url);
	}
	
	/**
	 * 新浪微博回调
	 */
	public function actionSinaCallback()
	{
		M::sina()->callbackHandler();
		///
		$this->_checkLogin();
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 验证登录状态
	 */
	private function _checkLogin()
	{
		$url = "";
		if ($this->mUser->isLogin()) {
			if (isset($_GET['taobao_url'])) 
				$url = str_replace("e35go", "e35go".$this->mUser->uId, trim($_GET['taobao_url']));
			else 
				$url = lpUrl::__('user/main');
		}
		
		///
echo <<< JS
<script language="javascript">
var url = "$url";
if (url != "") {
	//alert(url);
	//window.opener.location.reload();
	window.opener.location.href = url;
	window.close();
}
</script>
JS;
	}
}
